package demo4;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-04-08
 * Time: 16:03
 */
public class Test {      //力扣的 杨辉三角形
    public static List<List<Integer>> generate(int numRows) {
        List<List<Integer>> ret = new ArrayList<>();

        List<Integer> list = new ArrayList<>();
        list.add(1);

        ret.add(list);

        for (int i = 1; i < numRows; i++) {
            List<Integer> curRows = new ArrayList<>();
            curRows.add(1);
            //[i][j] = [i-1][j] + [i][j-1]
            for (int j = 1; j < i; j++) {
                curRows.add(ret.get(i - 1).get(j) + ret.get(i - 1).get(j - 1));
            }
            curRows.add(1);
            ret.add(curRows);
        }
        return ret;
    }

    public static void main(String[] args) {
        //List<List<Integer>> ret = new ArrayList<>();
        List<List<Integer>> ret = generate(5);
        System.out.println(ret);
        System.out.println("====");
    }
}
